import { useEffect, useState } from "react";

/**
 * 自定义hooks之-useTime
 */
function useTime() {
  const [time, setTime] = useState(new Date());

  useEffect(() => {
    const id = setInterval(() => {
      setTime(new Date());
    }, 1000);

    return () => clearInterval(id);
  }, []);

  return time;
}

export default useTime;
